﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using EntitiesContext;

namespace DAL
{
    internal static class MyConvert
    {
        public static MyGroup ToMyGroup(Group group)
        {
            MyGroup myGroup = new MyGroup()
            {
                GroupId = group.GroupId,
                GroupPrefearedLan = group.GroupPrefearedLan,
                Name = group.Name
            };

            return myGroup;
        }

        public static Group ToGroup(MyGroup myGroup)
        {
            Group group = new Group()
            {
                GroupPrefearedLan = myGroup.GroupPrefearedLan,
                Name = myGroup.Name
            };
            if (myGroup.GroupId != null)
            {
                group.GroupId = (int)myGroup.GroupId;
            }

            return group;
        }

        public static MyKeyboardKey ToMyKeyboardKey(KeyboardKey keyboardKey)
        {
            MyKeyboardKey myKeyboardKey = new MyKeyboardKey()
            {
                KeyAsciiCode = keyboardKey.KeyAsciiCode,
                MyOutputKey = MyConvert.ToMyOutputKey(keyboardKey.OutputKey),
                KeyboardKeyId = keyboardKey.KeyboardKeyId
            };

            return myKeyboardKey;
            //Note: Stopped here , changes needed to structure of DB and to classes including EF
        }

        public static MyOutputKey ToMyOutputKey(OutputKey outputKey)
        {
            MyOutputKey myOutputKey = new MyOutputKey()
            {
                MyGroup = MyConvert.ToMyGroup(outputKey.Group),
                KeyChar = outputKey.KeyChar[0],
                OutputKeyId = outputKey.OutputKeyId
            };

            return myOutputKey;
        }

        public static OutputKey ToOutputKey(MyOutputKey myOutputKey)
        {
            OutputKey outputKey = new OutputKey()
            {
                KeyChar = myOutputKey.KeyChar.ToString(),
                Group = MyConvert.ToGroup(myOutputKey.MyGroup),
            };
            if (myOutputKey.OutputKeyId != null)
            {
                outputKey.OutputKeyId = (int)myOutputKey.OutputKeyId;
            }

            return outputKey;
        }
    }
}
